package client.ui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import client.engine.ChatEngine;

/*
 * Lance: This class has been replaced by the corresponding class in the defaultTheme package
 */
@Deprecated
public class LoginFrame extends JFrame{
	
JTextField loginUserName;
JPasswordField passwordField;
ChatEngine myClient;

JTextField loginUserName2;
JPasswordField passwordField2;


public LoginFrame(ChatEngine client)
{
	myClient = client;
	setTitle("Parlanchin");	
	setSize(300,500);
	setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	buildUI();
	
}

private void buildUI()
{
	JTabbedPane tab = new JTabbedPane();
	getContentPane().add(tab,BorderLayout.CENTER);
	
	JPanel Lpanel = new JPanel();
	JPanel rPanel = new JPanel();
	
	GridBagLayout layout = new GridBagLayout();
	Lpanel.setLayout(layout);
	
	GridBagLayout layout2 = new GridBagLayout();
	rPanel.setLayout(layout);
	
	JLabel userName = new JLabel("Screen Name: ");
	layout.setConstraints(
			userName,
			new GridBagConstraints(
					1, 0, 0, 0, 1.0, 0.0,
					GridBagConstraints.WEST, GridBagConstraints.BOTH,
					new Insets(70, 0, 0, 150), 0, 0));
	
	Lpanel.add(userName);
	
	JLabel password = new JLabel("Password: ");
	layout.setConstraints(
			password,
			new GridBagConstraints(
					1, 0, 0, 0, 1.0, 0.0,
					GridBagConstraints.WEST, GridBagConstraints.BOTH,
					new Insets(150, 0, 0, 200), 0, 0));
	
	Lpanel.add(password);

	loginUserName = new JTextField();
	layout.setConstraints(
			loginUserName,
			new GridBagConstraints(
				1, 1, 0, 0, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(315, 85, 235, 0), 0, 0));
	Lpanel.add(loginUserName);
	
	passwordField = new JPasswordField();
	layout.setConstraints(
			passwordField,
			new GridBagConstraints(
				1, 1, 0, 0, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(350, 85, 200, 0), 0, 0));
	Lpanel.add(passwordField);
	
	JButton loginButton = new JButton("Login");
	layout.setConstraints(
			loginButton,
			new GridBagConstraints(
				2, 2, 0, 0, 1.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(450, 70, 100, 70), 0, 0));
	Lpanel.add(loginButton);

	loginButton.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					String signOnUsername = loginUserName.getText();
					String signOnPassword = passwordField.getText();
					myClient.getProducer().sendSignOnRequest(signOnUsername, signOnPassword);
					System.out.println(signOnPassword);
				}
			});
	
	
	//JButton test = new JButton("Register");
	
	JLabel newUsername = new JLabel("Screen Name: ");
	layout.setConstraints(
			newUsername,
			new GridBagConstraints(
					1, 0, 0, 0, 1.0, 0.0,
					GridBagConstraints.WEST, GridBagConstraints.BOTH,
					new Insets(70, 0, 0, 150), 0, 0));
	
	rPanel.add(newUsername);
	
	JLabel newPassword = new JLabel("Password: ");
	layout.setConstraints(
			newPassword,
			new GridBagConstraints(
					1, 0, 0, 0, 1.0, 0.0,
					GridBagConstraints.WEST, GridBagConstraints.BOTH,
					new Insets(150, 0, 0, 200), 0, 0));
	
	rPanel.add(newPassword);

	loginUserName2 = new JTextField();
	layout.setConstraints(
			loginUserName2,
			new GridBagConstraints(
				1, 1, 0, 0, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(315, 85, 235, 0), 0, 0));
	rPanel.add(loginUserName2);
	
	passwordField2 = new JPasswordField();
	layout.setConstraints(
			passwordField2,
			new GridBagConstraints(
				1, 1, 0, 0, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(350, 85, 200, 0), 0, 0));
	rPanel.add(passwordField2);
	
	JButton registerButton = new JButton("Register New Account");
	layout.setConstraints(
			registerButton,
			new GridBagConstraints(
				2, 2, 0, 0, 1.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(450, 70, 100, 70), 0, 0));
	rPanel.add(registerButton);
	
	registerButton.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					String registerUsername = loginUserName2.getText();
					String registerPassword = passwordField2.getText();
					
					myClient.getProducer().sendNewAccountRequest(registerUsername, registerPassword);
				}
			});
	
	tab.add("Login", Lpanel);
	tab.add("Register", rPanel);
	
	
}
}
